﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-27>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：全年情况查询
//********************************************************************************//
using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.UI;
using Entity.YS;
using Web.Class;

namespace Web.Pages.YongShui._12.ChaXunGL
{
    public partial class QuanNianQKCX : BasePage
    {
        #region 属性

        /// <summary>
        /// 保存结果集1
        /// </summary>
        private DataTable dtYongHuXXTab1
        {
            get
            {
                return ViewState["dtYongHuXXTab1"] as DataTable;
            }
            set
            {
                ViewState["dtYongHuXXTab1"] = value;
            }
        }

        /// <summary>
        /// 保存结果集2_1
        /// </summary>
        private DataTable dtQuanNianYSQKTab2_1
        {
            get
            {
                return ViewState["dtQuanNianYSQKTab2_1"] as DataTable;
            }
            set
            {
                ViewState["dtQuanNianYSQKTab2_1"] = value;
            }
        }
        /// <summary>
        /// 保存结果集2_2
        /// </summary>
        private DataTable dtQuanNianYSQKTab2_2
        {
            get
            {
                return ViewState["dtQuanNianYSQKTab2_2"] as DataTable;
            }
            set
            {
                ViewState["dtQuanNianYSQKTab2_2"] = value;
            }
        }
        /// <summary>
        /// 保存结果集3
        /// </summary>
        private DataTable dtYueYongSQKtab3
        {
            get
            {
                return ViewState["dtYueYongSQKtab3"] as DataTable;
            }
            set
            {
                ViewState["dtYueYongSQKtab3"] = value;
            }
        }

        /// <summary>
        /// 保存结果集4
        /// </summary>
        private DataTable dtYueYongSQKHZtab4
        {
            get
            {
                return ViewState["dtYueYongSQKHZtab4"] as DataTable;
            }
            set
            {
                ViewState["dtYueYongSQKHZtab4"] = value;
            }
        }
        /// <summary>
        /// 保存结果集5
        /// </summary>
        private DataTable dtYongHuSFQKtab5
        {
            get
            {
                return ViewState["dtYongHuSFQKtab5"] as DataTable;
            }
            set
            {
                ViewState["dtYongHuSFQKtab5"] = value;
            }
        }

        /// <summary>
        /// 保存结果集5_2
        /// </summary>
        private DataTable dtYongHuSFQKtab5_2
        {
            get
            {
                return ViewState["dtYongHuSFQKtab5_2"] as DataTable;
            }
            set
            {
                ViewState["dtYongHuSFQKtab5_2"] = value;
            }
        }

        /// <summary>
        /// 保存结果集6
        /// </summary>
        private DataTable dtQuanNianSFHZtab6
        {
            get
            {
                return ViewState["dtQuanNianSFHZtab6"] as DataTable;
            }
            set
            {
                ViewState["dtQuanNianSFHZtab6"] = value;
            }
        }

        /// <summary>
        /// 保存结果集7
        /// </summary>
        private DataTable dtYeWuYSFQKtab7
        {
            get
            {
                return ViewState["dtYeWuYSFQKtab7"] as DataTable;
            }
            set
            {
                ViewState["dtYeWuYSFQKtab7"] = value;
            }
        }
        /// <summary>
        /// 保存结果集8
        /// </summary>
        private DataTable dtXinKaoHYHHZtab8
        {
            get
            {
                return ViewState["dtXinKaoHYHHZtab8"] as DataTable;
            }
            set
            {
                ViewState["dtXinKaoHYHHZtab8"] = value;
            }
        }
        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int yonghuXXTab1_ID
        {
            get
            {
                return Convert.ToInt32(ViewState["yonghuXXTab1_ID"]);
            }
            set
            {
                ViewState["yonghuXXTab1_ID"] = value;
            }
        }
        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int yonghuXXTab2_ID
        {
            get
            {
                return Convert.ToInt32(ViewState["yonghuXXTab2_ID"]);
            }
            set
            {
                ViewState["yonghuXXTab2_ID"] = value;
            }
        }
        /// <summary>
        /// 水量年月
        /// </summary>
        ///  /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int i_ym
        {
            get
            {
                return Convert.ToInt32(ViewState["i_ym"]);
            }
            set
            {
                ViewState["i_ym"] = value;
            }
        }
        #endregion

        #region 变量

        /// <summary>
        /// 用户信息
        /// </summary>
        YS_YG_YONGHUXX _YS_YG_YONGHUXX = new YS_YG_YONGHUXX();

        /// <summary>
        /// 用户信息bll
        /// </summary>
        YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();

        /// <summary>
        /// 管理部门
        /// </summary>
        YS_JX_ZHANDIAN _YS_JX_ZHANDIAN = new YS_JX_ZHANDIAN();

        /// <summary>
        /// 管理部门bll
        /// </summary>
        YS_JX_ZHANDIANBLL _YS_JX_ZHANDIANBLL = new YS_JX_ZHANDIANBLL();

        /// <summary>
        /// 管理块
        /// </summary>
        YS_JX_GUANLIK _YS_JX_GUANLIK = new YS_JX_GUANLIK();

        /// <summary>
        /// 管理块BLL
        /// </summary>
        YS_JX_GUANLIKBLL _YS_JX_GUANLIKBLL = new YS_JX_GUANLIKBLL();

        /// <summary>
        /// 局信息BLL
        /// </summary>
        YS_JX_JUXINXBLL _YS_JX_JUXINXBLL = new YS_JX_JUXINXBLL();

        /// <summary>
        /// 公司信息BLL
        /// </summary>
        YS_JX_GONGSIXXBLL _YS_JX_GONGSIXXBLL = new YS_JX_GONGSIXXBLL();

        /// <summary>
        /// 行政区bll
        /// </summary>
        YS_JX_XINGZHENGQBLL _YS_JX_XINGZHENGQBLL = new YS_JX_XINGZHENGQBLL();
        /// <summary>
        /// 配置表bll
        /// </summary>
        S_WORDSBLL _S_WORDSBLL = new S_WORDSBLL();
        /// <summary>
        /// 存储过程调用类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }
            //switch (ASPxPageControl1.ActiveTabIndex)
            //{
            //    case 0:
            //        gvYongHuXXTab1.DataSource = this.dtYongHuXXTab1;
            //        gvYongHuXXTab1.DataBind();
            //        break;
            //    case 1:
            //        this.gvQuanNianYSQKtab2.DataSource = this.dtQuanNianYSQKTab2_1;
            //        this.gvQuanNianYSQKtab2.DataBind();
            //        break;
            //    case 2:
            //        this.gvYueYongSQKtab3.DataSource = this.dtYueYongSQKtab3;
            //        this.gvYueYongSQKtab3.DataBind();
            //        break;
            //    case 3:
            //        this.gvYueYongSHZtab4.DataSource = this.dtYueYongSQKHZtab4;
            //        this.gvYueYongSHZtab4.DataBind();
            //        break;
            //    case 4:
            //        this.gvJiHuaBGtab5.DataSource = this.dtYongHuSFQKtab5;
            //        this.gvJiHuaBGtab5.DataBind();
            //        break;
            //    case 5:
            //        this.gvQuanNianSFHZtab6.DataSource = this.dtQuanNianSFHZtab6;
            //        this.gvQuanNianSFHZtab6.DataBind();
            //        break;
            //    case 6:
            //        this.gvYeWuYSFQKtab7.DataSource = this.dtYeWuYSFQKtab7;
            //        this.gvYeWuYSFQKtab7.DataBind();
            //        break;
            //    case 7:
            //        gvXinKaoHYHHZtab8.DataSource = dtXinKaoHYHHZtab8;
            //        gvXinKaoHYHHZtab8.DataBind();
            //        break;
            //    default: break;
            //}
            this.gvYongHuXXTab1.DataSource = this.dtYongHuXXTab1;
            this.gvYongHuXXTab1.DataBind();
            this.gvQuanNianYSQKtab2.DataSource = this.dtQuanNianYSQKTab2_1;
            this.gvQuanNianYSQKtab2.DataBind();
            this.gvYueYongSQKtab3.DataSource = this.dtYueYongSQKtab3;
            this.gvYueYongSQKtab3.DataBind();
            this.gvYueYongSHZtab4.DataSource = this.dtYueYongSQKHZtab4;
            this.gvYueYongSHZtab4.DataBind();
            this.gvJiHuaBGtab5.DataSource = this.dtYongHuSFQKtab5;
            this.gvJiHuaBGtab5.DataBind();
            this.gvQuanNianSFHZtab6.DataSource = this.dtQuanNianSFHZtab6;
            this.gvQuanNianSFHZtab6.DataBind();
            this.gvYeWuYSFQKtab7.DataSource = this.dtYeWuYSFQKtab7;
            this.gvYeWuYSFQKtab7.DataBind();
            this.gvXinKaoHYHHZtab8.DataSource = dtXinKaoHYHHZtab8;
            this.gvXinKaoHYHHZtab8.DataBind();
        }

        /// <summary>
        /// 绑定空表头
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender);
        }

        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaXun_Click(object sender, EventArgs e)
        {
            int index = ASPxPageControl1.ActiveTabIndex;
            //PageTools.AlertMsg(this, i.ToString());
            ActiveTabIndexChange(index);
        }

        /// <summary>
        /// 管理部门下拉改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmbGuanLiBM_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbGuanLiK.Items.Clear();
            cmbGuanLiK.Items.Add("全部", "");
            cmbGuanLiK.SelectedIndex = 0;
            string glbm_now = cmbGuanLiBM.Value != null ? cmbGuanLiBM.Value.ToString() : "全部";
            InitDataAgain(glbm_now);
        }

        /// <summary>
        /// 表格点击行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvYongHuXXTab1_FocusedRowChanged(object sender, EventArgs e)
        {
            if (this.dtYongHuXXTab1 != null && this.dtYongHuXXTab1.Rows.Count > 0)
            {
                this.yonghuXXTab1_ID = Convert.ToInt32(this.gvYongHuXXTab1.GetRowValues(this.gvYongHuXXTab1.FocusedRowIndex, "ID"));
                SetData();
            }
        }

        /// <summary>
        /// tab2下拉框改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmbHuJiGDLX_SelectedIndexChanged(object sender, EventArgs e)
        {
            //LoadGridDataTab2();
        }
        protected void gvQuanNianYSQK2tab2_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            string s_yonghuh = "";

            if (hdCollection.Contains("quannian_yonghuh"))
            {
                object s = hdCollection.Get("quannian_yonghuh");

                int y = 0;

                DataTable dt = null;
                var yongshuijl = new List<YS_YONGSHUISJ>();
                if (s != null)
                {
                    if (!int.TryParse(txtYear.Text, out y))
                    {
                        y = 0;
                    }
                    string where = " and s_yonghuh='{0}' and i_y={1} and i_jlzt=0 order by i_m ";
                    where = string.Format(where, s, y);
                    DataSet ds = _SpHelper.P_YS_CX_YONGHUYSSJBYWHERE(where);
                    dt = ds.Tables[0];
                    yongshuijl = GetYongShuiSJ(dt);
                }
                gvQuanNianYSQK2tab2.DataSource = yongshuijl;
                gvQuanNianYSQK2tab2.DataBind();
            }
        }
        #endregion

        #region 方法

        private List<YS_YONGSHUISJ> GetYongShuiSJ(DataTable dt)
        {
            var yongshuisj = new List<YS_YONGSHUISJ>();
            foreach (DataRow row in dt.Rows)
            {
                var ys = new YS_YONGSHUISJ
                {
                    I_CHAOJIHSL = Convert.ToInt32(row["I_CHAOJIHSL"]),
                    I_CHUTIAOZ = Convert.ToInt32(row["I_CHUTIAOZ"]),
                    I_GUBIAOS = Convert.ToInt32(row["I_GUBIAOS"]),
                    I_HUIGUANL = Convert.ToInt32(row["I_HUIGUANL"]),
                    I_JIAJIAL = Convert.ToInt32(row["I_JIAJIAL"]),
                    I_JIJIANJH = Convert.ToInt32(row["I_JIJIANJH"]),
                    I_JUTIAOZ = Convert.ToInt32(row["I_JUTIAOZ"]),
                    I_M = Convert.ToInt32(row["I_M"]),
                    Month = Convert.ToString(row["I_M"]),
                    I_SHIYONGJH = Convert.ToInt32(row["I_SHIYONGJH"]),
                    I_SHIYONGSL = Convert.ToInt32(row["I_SHIYONGSL"]),
                    I_WAIGONGJH = Convert.ToInt32(row["I_WAIGONGJH"]),
                    I_YUANJIHUA = Convert.ToInt32(row["I_YUANJIHUA"]),
                    N_JIAJIAJE = Convert.ToDecimal(row["N_JIAJIAJE"])
                };
                yongshuisj.Add(ys);
            }

            for (int i = 1; i <= 12; i++)
            {
                var month = i;
                var y = yongshuisj.FirstOrDefault(s => s.I_M == month);
                if (y == null)
                {
                    y = new YS_YONGSHUISJ {I_M = month,Month = month.ToString()};
                    yongshuisj.Add(y);
                }
            }
            yongshuisj = yongshuisj.OrderBy(s => s.I_M).ToList();
            var heji = new YS_YONGSHUISJ
            {
                I_CHAOJIHSL = yongshuisj.Sum(s => s.I_CHAOJIHSL),
                I_CHUTIAOZ = yongshuisj.Sum(s => s.I_CHUTIAOZ),
                I_GUBIAOS = yongshuisj.Sum(s => s.I_GUBIAOS),
                I_HUIGUANL = yongshuisj.Sum(s => s.I_HUIGUANL),
                I_JIAJIAL = yongshuisj.Sum(s => s.I_JIAJIAL),
                I_JIJIANJH = yongshuisj.Sum(s => s.I_JIJIANJH),
                I_JUTIAOZ = yongshuisj.Sum(s => s.I_JUTIAOZ),
                I_M = 13,
                Month = "合计",
                I_SHIYONGJH = yongshuisj.Sum(s => s.I_SHIYONGJH),
                I_SHIYONGSL = yongshuisj.Sum(s => s.I_SHIYONGSL),
                I_WAIGONGJH = yongshuisj.Sum(s => s.I_WAIGONGJH),
                I_YUANJIHUA = yongshuisj.Sum(s => s.I_YUANJIHUA),
                N_JIAJIAJE = yongshuisj.Sum(s => s.N_JIAJIAJE)
            };
            yongshuisj.Add(heji);

            return yongshuisj;
        }
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            gvYongHuXXTab1.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvQuanNianYSQKtab2.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvYueYongSQKtab3.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvYueYongSHZtab4.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvJiHuaBGtab5.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvQuanNianSFHZtab6.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvYeWuYSFQKtab7.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvXinKaoHYHHZtab8.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;


            //水量年月
            string water_y_m = BusinessTool.YS_GETSETTINGSVALUE(eSETTINGS_KEYNAME.WATER_Y_M.ToString());
            this.i_ym = Convert.ToInt32(water_y_m);
            cbmYueShutab3.SelectedIndex = (this.i_ym % 100 - 1);
            txtYear.Text = (this.i_ym / 100).ToString();
            cbmHuiZongLX2tab4.Value = Convert.ToInt32(water_y_m) % 100;
            cbmYueShutab5.Value = Convert.ToInt32(water_y_m) % 100;
            //管理部门
            DataTable dtGuanLiBM = _YS_JX_ZHANDIANBLL.SelectYS_JX_ZHANDIANsAll();
            for (int i = 0; i < dtGuanLiBM.Rows.Count; i++)
            {
                if (dtGuanLiBM.Rows[i]["S_ZHANDIANMC"].ToString() != "中心")
                {
                    cmbGuanLiBM.Items.Add(dtGuanLiBM.Rows[i]["S_ZHANDIANMC"].ToString(), dtGuanLiBM.Rows[i]["S_ZHANDIANBH"].ToString());
                }
            }
            //业务员
            LoadYWY();
            //公司信息 局信息
            LoadJXX_GSXX();
            //行政区
            LoadXingZhengQ();
            //用水性质，涉水对象
            LoadYSXZ_SSDX();

            LoadShuiL();
            int userid = LoginInfo.CurrentUser.UserID;
            string username = LoginInfo.CurrentUser.UserName;
            //根据操作人加载管理部门(站点)
            DataTable dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANBH", "ROLEID", null, string.Format("USERID={0}", userid)).Tables[0];
            string zhandian = dtZhanDian.Rows[0]["TEXT"].ToString();//站点
            string roleid = dtZhanDian.Rows[0]["VALUE"].ToString();//9001 业务员，3001 办事处主任
            if (roleid == "9001")
            {
                if (zhandian == "00")
                {
                    cmbYeWuY.Enabled = false;
                    cmbYeWuY.Text = username;
                }
                else
                {
                    cmbGuanLiBM.Enabled = false;
                    cmbYeWuY.Enabled = false;
                    cmbGuanLiBM.Value = zhandian;
                    cmbYeWuY.Text = username;
                    //管理块
                    DataTable dtGuanLiK = _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", zhandian), null);
                    for (int i = 0; i < dtGuanLiK.Rows.Count; i++)
                    {
                        cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(), dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                    }
                }
            }
            else if (roleid == "3001" || roleid == "4001")
            {
                cmbGuanLiBM.Enabled = false;
                cmbGuanLiBM.Value = zhandian;
                //管理块
                DataTable dtGuanLiK = _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", zhandian), null);
                for (int i = 0; i < dtGuanLiK.Rows.Count; i++)
                {
                    cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(), dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                }
                LoadYWY();
            }
        }
        /// <summary>
        /// 再次根据管理部门初始化查询条件
        /// </summary>
        /// <param name="glbm">管理部门</param>
        private void InitDataAgain(string glbm)
        {
            if (glbm != "全部")
            {
                //管理块
                DataTable dtGuanLiK = _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", glbm), null);
                for (int i = 0; i < dtGuanLiK.Rows.Count; i++)
                {
                    cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(), dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                }
                //业务员
                LoadYWY();
            }
            else
            {
                cmbYeWuY.Items.Clear();
                //业务员
                LoadYWY();
            }


        }
        /// <summary>
        /// 加载局信息和公司信息
        /// </summary>
        private void LoadJXX_GSXX()
        {
            DataTable dt_jxx = _YS_JX_JUXINXBLL.SelectYS_JX_JUXINXesDynamic("i_leixing=0 and i_jlzt=0", null);
            for (int i = 0; i < dt_jxx.Rows.Count; i++)
            {
                cbmJuXX.Items.Add(dt_jxx.Rows[i]["S_BIANHAO"].ToString() + "_" + dt_jxx.Rows[i]["S_MINGCHENG"].ToString(), dt_jxx.Rows[i]["S_BIANHAO"]);
            }

            DataTable dt_gsxx = _YS_JX_GONGSIXXBLL.SelectYS_JX_GONGSIXXesDynamic("i_leixing=0 and i_jlzt=0", null);
            for (int i = 0; i < dt_gsxx.Rows.Count; i++)
            {
                cmbGongSiXX.Items.Add(dt_gsxx.Rows[i]["S_BIANHAO"].ToString() + "_" + dt_gsxx.Rows[i]["S_MINGCHENG"].ToString(), dt_gsxx.Rows[i]["S_BIANHAO"]);
            }
        }
        /// <summary>
        /// 加载行政区
        /// </summary>
        private void LoadXingZhengQ()
        {
            DataTable dtXingZhengQ = _YS_JX_XINGZHENGQBLL.SelectYS_JX_XINGZHENGQsDynamic("i_jlzt=0", " s_bianhao");
            for (int i = 0; i < dtXingZhengQ.Rows.Count; i++)
            {
                cmbXingZhengQ.Items.Add(dtXingZhengQ.Rows[i]["s_bianhao"] + "_" + dtXingZhengQ.Rows[i]["S_MINGCHENG"].ToString(), dtXingZhengQ.Rows[i]["s_bianhao"]);
            }
        }
        /// <summary>
        /// 加载用水性质、涉水对象
        /// </summary>
        private void LoadYSXZ_SSDX()
        {
            //用水性质
            DataTable dt_ysxz = _SpHelper.P_YSCX_YSXZ_SSDX(1).Tables[0];
            for (int i = 0; i < dt_ysxz.Rows.Count; i++)
            {
                cmbYongShuiXZ.Items.Add(dt_ysxz.Rows[i]["XH"].ToString() + "_" + dt_ysxz.Rows[i]["NA"].ToString(), dt_ysxz.Rows[i]["XH"]);
            }
            //涉水对象
            DataTable dt_ssdx = _SpHelper.P_YSCX_YSXZ_SSDX(3).Tables[0];
            for (int i = 0; i < dt_ssdx.Rows.Count; i++)
            {
                cmbSheShuiDXFL_h1.Items.Add(dt_ssdx.Rows[i]["XH"].ToString() + "_" + dt_ssdx.Rows[i]["NA"].ToString(), dt_ssdx.Rows[i]["XH"]);
            }

        }
        /// <summary>
        /// 根据站点加载业务员
        /// </summary>
        private void LoadYWY()
        {
            DataTable dtYWY = BusinessTool.GetTextAndValue(
                "View_AS_UserInfo", "USERNAME", "USERID", null, this.cmbGuanLiBM.SelectedIndex == 0 ? "ROLENAME like '%业务员%' and department!=313" : string.Format("ZHANDIANBH='{0}' and ROLENAME like '%业务员%' and department!=313", this.cmbGuanLiBM.Value)
                 ).Tables[0];
            DataRow drTemp = dtYWY.NewRow();
            drTemp[0] = "";
            drTemp[1] = 0;
            dtYWY.Rows.InsertAt(drTemp, 0);
            PageTools.BindComboBox(
                this.cmbYeWuY, dtYWY
            );
            if (this.cmbYeWuY.Items.Count != 0)
            {
                this.cmbYeWuY.SelectedIndex = 0;
            }
        }
        /// <summary>
        /// 加载水量
        /// </summary>
        private void LoadShuiL()
        {
            string[] arr = new string[] { "原计划量", "基建量", "外供量", "局调整量", "处调整量", "现计划量", "实用量", "超用量", "加价量", "回灌量", "超用率", "加价率", "完成率" };
            string[] arrvalue = new string[] { "I_YUANJIHUA", "I_JIJIANJH", "I_WAIGONGJH", "I_JUTIAOZ", "I_CHUTIAOZ", "I_SHIYONGJH", "I_SHIYONGSL", "I_CHAOJIHSL", "I_JIAJIAL", "I_HUIGUANL", "I_CHAOJIHSL/(I_YUANJIHUA+I_JIJIANJH+I_WAIGONGJH)", "N_JIAJIAJE/N_CHAOJIHJE", "I_SHIYONGSL/(I_YUANJIHUA+I_JIJIANJH+I_WAIGONGJH)" };
            for (int i = 0; i < arr.Length; i++)
            {
                //cmbShuiLiangtab2.Items.Add(arr[i]);
                //cmbShuiLiangtab3.Items.Add(arr[i]);
                cmbShuiLiangtab3.Items.Add(arr[i], arrvalue[i]);
                cmbShuiLiangtab2.Items.Add(arr[i], arrvalue[i]);
            }
        }
        /// <summary>
        /// 跟当前显示的tab也签选择查询的数据集
        /// </summary>
        /// <param name="index"></param>
        private void ActiveTabIndexChange(int index)
        {
            string v_zhandian = "", v_guanlikuai = "";
            string v_ywy = cmbYeWuY.SelectedIndex <= 0 ? null : cmbYeWuY.Value.ToString();
            string type = "";
            string value = "";
            //站点
            if (cmbGuanLiBM.Value != null)
            {
                v_zhandian = cmbGuanLiBM.Value.ToString();
            }
            //管理块
            if (cmbGuanLiK.Value != null)
            {
                v_guanlikuai = cmbGuanLiK.Value.ToString();
            }

            //用户号、用户名、
            if (rbnYongHuH.Checked && txtYongHuH.Text.Trim() != "")
            {
                type = "v_yonghuh";
                value = txtYongHuH.Text;
            }
            else if (rbnYongHuM.Checked && txtYongHuM.Text.Trim() != "")
            {
                type = "v_yonghum";
                value = txtYongHuM.Text;
            }
            switch (index)
            {
                case 0:
                    LoadGridDataTab1(v_zhandian, v_guanlikuai, v_ywy);
                    break;
                case 1:
                    LoadGridDataTab2(v_zhandian, v_guanlikuai, v_ywy, type, value);
                    break;
                case 2:
                    LoadGridDataTab3(v_zhandian, v_guanlikuai, v_ywy, type, value);
                    break;
                case 3:
                    LoadGridDataTab4(v_zhandian, v_guanlikuai, v_ywy, type, value);
                    break;
                case 4:
                    LoadGridDataTab5(v_zhandian, v_guanlikuai, v_ywy, type, value);
                    break;
                case 5:
                    LoadGridDataTab6(v_zhandian, v_guanlikuai, v_ywy, type, value);
                    break;
                case 6:
                    LoadGridDataTab7(v_zhandian, v_guanlikuai, v_ywy, type, value);
                    break;
                case 7:
                    LoadGridDataTab8(v_zhandian, v_guanlikuai, v_ywy, type, value);
                    break;
                default: break;
            }
        }

        /// <summary>
        /// 加载查询数据
        /// </summary>
        private void LoadGridDataTab1(string v_zhandian, string v_guanlikuai, string v_ywy)
        {
            string v_yonghuh = "", v_yonghum = "", v_yonghudz = "";
            string v_yongshuixz = "";
            string v_sheshuidx = "";
            string v_shikaohy = "";
            string v_yongshuij = "";
            string v_juxx = "";
            string v_gongsixx = "";
            string v_kaihuhm = "";
            string v_yinhangzh = "";


            //用户号、用户名、用户地址
            if (rbnYongHuH.Checked && txtYongHuH.Text.Trim() != "")
            {
                v_yonghuh = txtYongHuH.Text;
            }
            else if (rbnYongHuM.Checked && txtYongHuM.Text.Trim() != "")
            {
                v_yonghum = txtYongHuM.Text;
            }
            if (rbnYongHuDZ.Checked && txtYongHuDZ.Text.Trim() != "")
            {
                v_yonghudz = txtYongHuDZ.Text;
            }
            else if (rbnYongShuiXZ.Checked && cmbYongShuiXZ.Text.Trim() != "")//用水性质
            {
                v_yongshuixz = cmbYongShuiXZ.Value.ToString();
            }
            else if (rbnSheShuiDXFL.Checked && cmbSheShuiDXFL_h1.Text.Trim() != "")//涉水对象分类
            {
                v_sheshuidx = "='" + cmbSheShuiDXFL_h1.Value.ToString() + "'";
            }
            else if (rbnShiKaoHY.Checked && txtShiKaoHY.Text.Trim() != "")//试考核月
            {
                v_shikaohy = cbmShiKaoHY.Text + txtShiKaoHY.Text;
            }
            else if (rbnJuXX.Checked && cbmJuXX.Text.Trim() != "")//局信息
            {
                v_juxx = cbmJuXX.Value.ToString();
            }
            else if (rbnGongSiXX.Checked && cmbGongSiXX.Text.Trim() != "")//公司信息
            {
                v_gongsixx = cmbGongSiXX.Value.ToString();
            }

            this.dtYongHuXXTab1 = _SpHelper.P_YSCX_YHXXCX(v_zhandian, v_guanlikuai, v_ywy, txtYear.Text==""?this.i_ym: Convert.ToInt32(txtYear.Text), v_yonghuh, v_yonghum, v_yonghudz,
                2, v_yongshuixz, v_sheshuidx, v_shikaohy, v_yongshuij, v_juxx, v_gongsixx, v_kaihuhm, v_yinhangzh, 0, "").Tables[0];
            gvYongHuXXTab1.DataSource = this.dtYongHuXXTab1;
            gvYongHuXXTab1.DataBind();
            if (this.dtYongHuXXTab1 != null && this.dtYongHuXXTab1.Rows.Count > 0)
            {
                gvYongHuXXTab1.FocusedRowIndex = -1;
                gvYongHuXXTab1.FocusedRowIndex = 0;
            }
            lbzjltab1.Text = "共" + this.dtYongHuXXTab1.Rows.Count + "笔";
            //SetData();
        }

        /// <summary>
        /// 给显示框赋值
        /// </summary>
        private void SetData()
        {
            DataTable dt_temp = _SpHelper.P_YSCX_YHXXCX("", "", "", Convert.ToInt32(txtYear.Text), "", "", "", 2, "", "", "", "", "", "", "", "", this.yonghuXXTab1_ID == 0 ? -1 : this.yonghuXXTab1_ID, "").Tables[0];
            if (dt_temp != null && dt_temp.Rows.Count > 0)
            {
                txtYongHuH2.Text = dt_temp.Rows[0]["用户号"].ToString();
                txtYongHuM2.Text = dt_temp.Rows[0]["用户名"].ToString();
                txtYongShuiXZ.Text = dt_temp.Rows[0]["用水性质"].ToString();
                txtHangYeLX.Text = dt_temp.Rows[0]["S_HANGYELEIXMC"].ToString();
                txtJuHao.Text = dt_temp.Rows[0]["局号"].ToString();
                txtJuMing.Text = dt_temp.Rows[0]["局名"].ToString();
                txtYongShuiJ2.Text = dt_temp.Rows[0]["用水价"].ToString();
                txtSheShuiDXFL.Text = dt_temp.Rows[0]["S_SHESHUIDXFLMC"].ToString();
                txtGongSiH.Text = dt_temp.Rows[0]["公司号"].ToString();
                txtGongSiM.Text = dt_temp.Rows[0]["公司名"].ToString();
                txtShouFeiFS.Text = dt_temp.Rows[0]["收费方式"].ToString();
                txtYeWuY.Text = dt_temp.Rows[0]["业务员"].ToString();
                txtXingZhengQH.Text = dt_temp.Rows[0]["行政区号"].ToString();
                txtXingZhengQM.Text = dt_temp.Rows[0]["行政区"].ToString();
                txtZiLaiSBS.Text = dt_temp.Rows[0]["I_ZLSBS"].ToString();
                txtHuiGuanBS.Text = dt_temp.Rows[0]["I_HGBS"].ToString(); ;
                txtShiKaoHY2.Text = dt_temp.Rows[0]["考核复用"].ToString();
                txtKaoHeFYBZ.Text = dt_temp.Rows[0]["考核复用"].ToString() == "0" ? "不考核" : dt_temp.Rows[0]["考核复用"].ToString() == "1" ? "工业" : "非工业";
                txtKaoHeFYBZ2.Text = dt_temp.Rows[0]["试考核月"].ToString();
                txtYongHuDZ2.Text = dt_temp.Rows[0]["用户地址"].ToString();
                txtLianXiBM.Text = dt_temp.Rows[0]["联系部门"].ToString();
                txtLianXiR.Text = dt_temp.Rows[0]["联系人"].ToString();
                txtLianXiDH.Text = dt_temp.Rows[0]["联系电话"].ToString();
                txtYouBian.Text = dt_temp.Rows[0]["邮编"].ToString();
                txtKaiHuHM2.Text = dt_temp.Rows[0]["开户户名"].ToString();
                txtKaiHuYH.Text = dt_temp.Rows[0]["开户银行"].ToString();
                txtYinHangZH2.Text = dt_temp.Rows[0]["银行账号"].ToString();

            }
            else
            {
                txtYongHuH2.Text = "";
                txtYongHuM2.Text = "";
                txtYongShuiXZ.Text = "";
                txtHangYeLX.Text = "";
                txtJuHao.Text = "";
                txtJuMing.Text = "";
                txtYongShuiJ2.Text = "";
                txtSheShuiDXFL.Text = "";
                txtGongSiH.Text = "";
                txtGongSiM.Text = "";
                txtShouFeiFS.Text = "";
                txtYeWuY.Text = "";
                txtXingZhengQH.Text = "";
                txtXingZhengQM.Text = "";
                txtZiLaiSBS.Text = "";
                txtHuiGuanBS.Text = "";
                txtShiKaoHY2.Text = "";
                txtKaoHeFYBZ.Text = "";
                txtKaoHeFYBZ2.Text = "";
                txtYongHuDZ2.Text = "";
                txtLianXiBM.Text = "";
                txtLianXiR.Text = "";
                txtLianXiDH.Text = "";
                txtYouBian.Text = "";
                txtKaiHuHM2.Text = "";
                txtKaiHuYH.Text = "";
                txtYinHangZH2.Text = "";

            }
        }
        /// <summary>
        /// 加载查询数据
        /// </summary>


        /// <summary>
        /// 加载tab2页签数据
        /// </summary>
        private void LoadGridDataTab2(string v_zhandian, string v_guanlikuai, string v_ywy, string type, string value)
        {
            int y = 0;//水量年
            int v_type = -1;//0-用户号 1-用户名
            int sllx = -1;//水量类型
            int jelx = -1;//金额类型
            int ys1 = txtYueShutab2.Text.Trim() != "" ? Convert.ToInt32(txtYueShutab2.Text) : 1;//水量月数
            int ys2 = txtYueShu2tab2.Text.Trim() != "" ? Convert.ToInt32(txtYueShu2tab2.Text) : 1;//金额月数
            int m = Convert.ToInt32(cbmYueShutab2.Value == null ? -1 : cbmYueShutab2.Value);//指定月

            if (!int.TryParse(txtYear.Text, out y))
            {
                y = 0;
            }
            if (type == "v_yonghuh")
            {
                v_type = 0;
            }
            else if (type == "v_yonghum")
            {
                v_type = 1;
            }
            //水量
            string slwhere = "";
            if (chkShuiLiangtab2.Checked)
            {
                //string sllx = cmbShuiLiangtab2.Text != "" ? cmbShuiLiangtab2.Text : "";
                //string slz1 = cbmShuiLiang1tab2.Text != "" && txtShuiLiang1tab2.Text != "" ? cbmShuiLiang1tab2.Text + txtShuiLiang1tab2.Text : "";
                //string slz2 = cbmShuiLiang2tab2.Text != "" && txtShuiLiang2tab2.Text != "" ? cbmShuiLiang2tab2.Text + txtShuiLiang2tab2.Text : "";
                int shuiliang1 = 0;
                if (cmbShuiLiangtab2.Value != null && cbmShuiLiang1tab2.Value != null && cbmShuiLiang1tab2.Text != "" 
                    && txtShuiLiang1tab2.Text != "" && int.TryParse(txtShuiLiang1tab2.Text, out shuiliang1))
                {
                    sllx = cmbShuiLiangtab2.SelectedIndex;
                    slwhere = cbmShuiLiang1tab2.Text + txtShuiLiang1tab2.Text;
                }
                else if (cmbShuiLiangtab2.Value != null && cbmShuiLiang2tab2.Value != null && cbmShuiLiang2tab2.Text != "" 
                    && txtShuiLiang2tab2.Text != "" && int.TryParse(txtShuiLiang2tab2.Text, out shuiliang1))
                {
                    sllx = cmbShuiLiangtab2.SelectedIndex;
                    slwhere = cbmShuiLiang2tab2.Text + txtShuiLiang2tab2.Text;
                }
                else if (cmbShuiLiangtab2.Value != null && cbmShuiLiang1tab2.Value != null && cbmShuiLiang1tab2.Text != "" && txtShuiLiang1tab2.Text != "" && int.TryParse(txtShuiLiang1tab2.Text, out shuiliang1)
                    && cbmShuiLiang2tab2.Value != null && cbmShuiLiang2tab2.Text != "" && txtShuiLiang2tab2.Text != "" && int.TryParse(txtShuiLiang2tab2.Text, out shuiliang1))
                {
                    sllx = cmbShuiLiangtab2.SelectedIndex;
                    slwhere = " between " + cbmShuiLiang1tab2.Text + " and " + txtShuiLiang2tab2.Text;
                }
            }
            //金额
            string jinewhere = "";
            if (chkJinEtab2.Checked)
            {
                //string jelx = cmbJinElxtab2.Text != "" ? cmbJinElxtab2.Text : "";
                //string je = cbmJinEtab2.Text != "" && txtJinEtab2.Text != "" ? cbmJinEtab2.Text + txtJinEtab2.Text : "";
                double txtje = 0;
                if (cmbJinElxtab2.Value != null && cbmJinEtab2.Text != null && txtJinEtab2.Text != "" && double.TryParse(txtJinEtab2.Text, out txtje))
                {
                    jelx = cmbJinElxtab2.SelectedIndex;
                    jinewhere = cbmJinEtab2.Text + txtJinEtab2.Text;
                }
            }
            this.dtQuanNianYSQKTab2_1 = _SpHelper.P_YS_CX_QUANNIANYSQKCX(v_zhandian, v_guanlikuai, v_ywy, v_type, value, y, m, slwhere, ys1, sllx, jinewhere, ys2, jelx).Tables[0];
            this.gvQuanNianYSQKtab2.DataSource = this.dtQuanNianYSQKTab2_1;
            this.gvQuanNianYSQKtab2.DataBind();
            if (gvQuanNianYSQKtab2.VisibleRowCount > 0)
            {
                gvQuanNianYSQKtab2.FocusedRowIndex = -1;
                gvQuanNianYSQKtab2.FocusedRowIndex = 0;
            }
            else
            {
                gvQuanNianYSQK2tab2.DataSource = null;
                gvQuanNianYSQK2tab2.DataBind();
            }
            lbzjltab2.Text = "共" + dtQuanNianYSQKTab2_1.Rows.Count + "笔";
            //exec dbo.用户全年用水情况  @userid='0100002',@username='上海煤气第一管线工程有限公司',@n_y='2015'
            //this.dtQuanNianYSQKTab2_2 = _SpHelper.P_YS_CX_QUANNIANYSQKCX(v_zhandian,v_guanlikuai,v_ywy,1,value,(this.i_ym/100),(this.i_ym%100),"S_YONGHUH",1,)
            //this.gvQuanNianYSQK2tab2.DataSource = this.dtQuanNianYSQKTab2_2;
            //this.gvQuanNianYSQK2tab2.DataBind();

        }

        /// <summary>
        /// 加载tab3页签数据
        /// </summary>
        private void LoadGridDataTab3(string v_zhandian, string v_guanlikuai, string v_ywy, string type, string value)
        {
            string sllx = ""; string slz1 = "";
            string slz2 = ""; int jelx = -1;
            string je = "";
            int y = 0;
            if (!int.TryParse(txtYear.Text, out y))
            {
                y = 0;
            }
            int m = 0;
            if (!int.TryParse(cbmYueShutab3.Text, out m))
            {
                m = 0;
            }
            string v_type = "-1";
            if (type == "v_yonghuh")
            {
                v_type = "0";
            }
            else if (type == "v_yonghum")
            {
                v_type = "1";
            }
            if (chkShuiLiangtab3.Checked)
            {
                //v_type = cmbShuiLiangtab3.SelectedIndex.ToString();
                //sllx = cmbShuiLiangtab3.Text != "" ? cmbShuiLiangtab3.Text : "";
                //slz1 = cbmShuiLiang1tab3.Text != "" && txtShuiLiang1tab3.Text != "" ? cbmShuiLiang1tab3.Text + txtShuiLiang1tab3.Text : "";
                //slz2 = cbmShuiLiang2tab3.Text != "" && txtShuiLiang2tab3.Text != "" ? cbmShuiLiang2tab3.Text + txtShuiLiang2tab3.Text : "";
                int shuiliang1 = 0;
                if (cmbShuiLiangtab3.SelectedIndex > -1 && cbmShuiLiang1tab3.Text != "" 
                    && txtShuiLiang1tab3.Text != "" && int.TryParse(txtShuiLiang1tab3.Text, out shuiliang1))
                {
                    slz1 = " and " + cmbShuiLiangtab3.Value + cbmShuiLiang1tab3.Text + txtShuiLiang1tab3.Text;
                }
                int shuiliang2 = 0;
                if (cmbShuiLiangtab3.SelectedIndex > -1 && cbmShuiLiang2tab3.Text != "" 
                    && txtShuiLiang2tab3.Text != "" && int.TryParse(txtShuiLiang2tab3.Text, out shuiliang2))
                {
                    slz2 = " and " + cmbShuiLiangtab3.Value + cbmShuiLiang2tab3.Text + txtShuiLiang2tab3.Text;
                }
            }

            if (chkJinEtab3.Checked)
            {
                //jelx = cmbJinELXtab3.Text != "" ? cmbJinELXtab3.Text : "";
                //je = cbmJinEtab3.Text != "" && txtJinEtab3.Text != "" ? cbmJinEtab3.Text + txtJinEtab3.Text : "";
                double txtje = 0;
                if (cmbJinELXtab3.Value != null && cbmJinEtab3.Text != "" && txtJinEtab3.Text != "" && double.TryParse(txtJinEtab3.Text, out txtje))
                {
                    jelx = cmbJinELXtab3.SelectedIndex;
                    je = " and " + cmbJinELXtab3.Value + cbmJinEtab3.Text + txtJinEtab3.Text;
                }
            }
            string ys = cbmYueShutab3.Value.ToString();//20190412 2改为3
            this.dtYueYongSQKtab3 = SearchSpHelper.P_YS_CX_YUEYONGSQK(v_zhandian, v_guanlikuai, v_ywy, v_type, value, y.ToString(), m.ToString(), slz1 + slz2, je).Tables[0];
            this.gvYueYongSQKtab3.DataSource = this.dtYueYongSQKtab3;
            this.gvYueYongSQKtab3.DataBind();
            int count = 0;
            if(dtYueYongSQKtab3.Rows.Count > 0)
            {
                count = dtYueYongSQKtab3.Select("I_HEJIL=0").Length;
            }
            lbzjltab3.Text = "共" + count.ToString() + "笔";//20190415
        }
        /// <summary>
        /// 加载tab4页签数据
        /// </summary>
        private void LoadGridDataTab4(string v_zhandian, string v_guanlikuai, string v_ywy, string type, string value)
        {
            int hzlx = Convert.ToInt32(cbmHuiZongLXtab4.Value); //20190415
            int ys = Convert.ToInt32(cbmHuiZongLX2tab4.Value);//20190415
            int y = 0;
            if (!int.TryParse(txtYear.Text, out y))
            {
                y = 0;
            }
            this.dtYueYongSQKHZtab4 = SearchSpHelper.P_YS_CX_YUEYONGSHZ(v_zhandian, v_guanlikuai, v_ywy, hzlx, y, ys).Tables[0];
            this.gvYueYongSHZtab4.DataSource = this.dtYueYongSQKHZtab4;
            this.gvYueYongSHZtab4.DataBind();
            int count = 0;
            if (dtYueYongSQKHZtab4.Rows.Count > 0)
            {
                count = dtYueYongSQKHZtab4.Select("I_HEJIL=0").Length;
            }
            lbzjltab4.Text = "共" + count.ToString() + "笔";//20190415
        }

        /// <summary>
        /// 加载tab5页签数据
        /// </summary>
        private void LoadGridDataTab5(string v_zhandian, string v_guanlikuai, string v_ywy, string type, string value)
        {
            int ys = cbmYueShutab5.Value.ToString() != "" ? Convert.ToInt32(cbmYueShutab5.Value) : 0;

            int y = 0;
            if (!int.TryParse(txtYear.Text, out y))
            {
                y = 0;
            }
            int v_type = -1;
            if (type == "v_yonghuh")
            {
                v_type = 0;
            }
            else if (type == "v_yonghum")
            {
                v_type = 1;
            }
            this.dtYongHuSFQKtab5 = SearchSpHelper.P_YS_CX_YONGHUSFQK(v_zhandian, v_guanlikuai, v_ywy, v_type, value, y, ys).Tables[0];
            this.gvJiHuaBGtab5.DataSource = this.dtYongHuSFQKtab5;
            this.gvJiHuaBGtab5.DataBind();
            if (gvJiHuaBGtab5.VisibleRowCount > 0)
            {
                gvJiHuaBGtab5.FocusedRowIndex = -1;
                gvJiHuaBGtab5.FocusedRowIndex = 0;
            }
            else
            {
                this.gvJiHuaBG2tab5.DataSource = null;
                this.gvJiHuaBG2tab5.DataBind();
            }
            lbzjltab5.Text = "共" + dtYongHuSFQKtab5.Rows.Count + "笔";
        }

        /// <summary>
        /// 加载tab6页签数据
        /// </summary>
        private void LoadGridDataTab6(string v_zhandian, string v_guanlikuai, string v_ywy, string type, string value)
        {
            int hzlx = Convert.ToInt32(cbmHuiZongLXtab6.Value); //20190415
            int y = 0;
            if (!int.TryParse(txtYear.Text, out y))
            {
                y = 0;
            }
            int ys = Convert.ToInt32(cbmYuetab6.Value);
            this.dtQuanNianSFHZtab6 = SearchSpHelper.P_YS_CX_QNSFHZ(v_zhandian, v_guanlikuai, v_ywy, hzlx, y, ys).Tables[0];
            this.gvQuanNianSFHZtab6.DataSource = this.dtQuanNianSFHZtab6;
            this.gvQuanNianSFHZtab6.DataBind();
            int count = 0;
            if (dtQuanNianSFHZtab6.Rows.Count > 0)
            {
                count = dtQuanNianSFHZtab6.Select("I_M=0").Length;
            }
            lbzjltab6.Text = "共" + count.ToString() + "笔";
        }

        /// <summary>
        /// 加载tab7页签数据
        /// </summary>
        private void LoadGridDataTab7(string v_zhandian, string v_guanlikuai, string v_ywy, string type, string value)
        {
            int y = 0;
            if (!int.TryParse(txtYear.Text, out y))
            {
                y = 0;
            }
            int ys = Convert.ToInt32(cbmYuetab7.Value); 
            this.dtYeWuYSFQKtab7 = SearchSpHelper.P_YS_CX_YEWUYQNSFQK(v_zhandian, v_guanlikuai, v_ywy, y, ys).Tables[0];
            this.gvYeWuYSFQKtab7.DataSource = this.dtYeWuYSFQKtab7;
            this.gvYeWuYSFQKtab7.DataBind();
            int count = 0;
            if (dtYeWuYSFQKtab7.Rows.Count > 0)
            {
                count = dtYeWuYSFQKtab7.Select("I_M=0").Length;
            }
            lbzjltab7.Text = "共" + count.ToString() + "笔";
        }
        /// <summary>
        /// 加载tab8页签数据
        /// </summary>
        private void LoadGridDataTab8(string v_zhandian, string v_guanlikuai, string v_ywy, string type, string value)
        {
            int y = 0;
            if (!int.TryParse(txtYear.Text, out y))
            {
                y = 0;
            }
            int v_type = -1;
            if (type == "v_yonghuh")
            {
                v_type = 0;
            }
            else if (type == "v_yonghum")
            {
                v_type = 1;
            }
            dtXinKaoHYHHZtab8 = SearchSpHelper.P_YS_CX_XINKAOHYHHZ_NEW(v_zhandian, v_guanlikuai, v_ywy, v_type.ToString(), value, y.ToString()).Tables[0];
            gvXinKaoHYHHZtab8.DataSource = dtXinKaoHYHHZtab8;
            gvXinKaoHYHHZtab8.DataBind();
        }

        /// <summary>
        /// 前台表格行改变事件回调方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            object id = this.hdCollection.Get("ID");
            string msg = "";
            if (e.Parameter == "setinfo")
            {
                DataTable dt_temp = _SpHelper.P_YSCX_YHXXCX("", "", "", Convert.ToInt32(txtYear.Text), "", "", "", 2, "", "", "", "", "", "", "", "", Convert.ToInt32(id), "").Tables[0];
                if (dt_temp != null && dt_temp.Rows.Count > 0)
                {
                    msg = string.Join("|", Convert.ToString(dt_temp.Rows[0]["用户号"]), Convert.ToString(dt_temp.Rows[0]["用户名"]), Convert.ToString(dt_temp.Rows[0]["用水性质"]),
                        Convert.ToString(dt_temp.Rows[0]["局号"]), Convert.ToString(dt_temp.Rows[0]["局名"]), Convert.ToString(dt_temp.Rows[0]["用水价"]), Convert.ToString(dt_temp.Rows[0]["S_SHESHUIDXFLMC"]),
                        Convert.ToString(dt_temp.Rows[0]["公司号"]), Convert.ToString(dt_temp.Rows[0]["公司名"]), Convert.ToString(dt_temp.Rows[0]["收费方式"]), Convert.ToString(dt_temp.Rows[0]["业务员"]),
                        Convert.ToString(dt_temp.Rows[0]["行政区号"]), Convert.ToString(dt_temp.Rows[0]["行政区"]), Convert.ToString(dt_temp.Rows[0]["考核复用"]), Convert.ToString(dt_temp.Rows[0]["试考核月"]),
                        Convert.ToString(dt_temp.Rows[0]["用户地址"]), Convert.ToString(dt_temp.Rows[0]["联系部门"]), Convert.ToString(dt_temp.Rows[0]["联系人"]), Convert.ToString(dt_temp.Rows[0]["联系电话"]),
                        Convert.ToString(dt_temp.Rows[0]["邮编"]), Convert.ToString(dt_temp.Rows[0]["开户户名"]), Convert.ToString(dt_temp.Rows[0]["开户银行"]), Convert.ToString(dt_temp.Rows[0]["银行账号"]),
                         Convert.ToString(dt_temp.Rows[0]["I_ZLSBS"]), Convert.ToString(dt_temp.Rows[0]["I_HGBS"]), Convert.ToString(dt_temp.Rows[0]["S_HANGYELEIXMC"]));
                }
                else
                {
                    msg = "||||||||||||||||||||||||||||||";
                }

            }
            //else if (e.Parameter == "xdjh")
            //{
            //    DataTable dt_temp_tab2 = _SpHelper.P_YSCX_JHCX_ALL(1, "", "", this.I_Y, -1, "", Convert.ToInt32(id)).Tables[0];
            //    if (dt_temp_tab2 != null && dt_temp_tab2.Rows.Count > 0)
            //    {
            //        msg = string.Join("|", Convert.ToString(dt_temp_tab2.Rows[0]["S_YONGHUH"]), Convert.ToString(dt_temp_tab2.Rows[0]["S_YONGHUM"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_M1"]),
            //             Convert.ToString(dt_temp_tab2.Rows[0]["I_M2"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_M3"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_M4"]),
            //             Convert.ToString(dt_temp_tab2.Rows[0]["I_M5"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_M6"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_M7"]),
            //             Convert.ToString(dt_temp_tab2.Rows[0]["I_M8"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_M9"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_M10"]),
            //             Convert.ToString(dt_temp_tab2.Rows[0]["I_M11"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_M12"]), Convert.ToString(dt_temp_tab2.Rows[0]["I_HEJI"]));
            //    }
            //}
            e.Result = e.Parameter + "|0|" + msg;
        }
        #endregion

        protected void gvJiHuaBG2tab5_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            string yonghuh = "";
            string yonghum = "";
            if (hdCollection.Contains("shoufei_yonghuh"))
            {
                yonghuh = hdCollection.Get("shoufei_yonghuh").ToString();
            }
            int y = 0;
            if (!int.TryParse(txtYear.Text, out y))
            {
                y = 0;
            }
            this.dtYongHuSFQKtab5_2 = SearchSpHelper.P_YS_CX_YONGHUQNSFQK(yonghuh, yonghum, y).Tables[0];
            this.gvJiHuaBG2tab5.DataSource = this.dtYongHuSFQKtab5_2;
            this.gvJiHuaBG2tab5.DataBind();
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            int index = ASPxPageControl1.ActiveTabIndex;
            string sName = "";
            if (index == 0)
            {
                gvYongHuXXTab1.DataSource = this.dtYongHuXXTab1;
                gvYongHuXXTab1.DataBind();
                ASPxGridViewExporter1.GridViewID = "gvYongHuXXTab1";
                sName = "用户信息";
                gvYongHuXXTab1.Settings.ShowFooter = false;
            }
            else if (index == 1)
            {
                gvQuanNianYSQKtab2.DataSource = this.dtQuanNianYSQKTab2_1;
                gvQuanNianYSQKtab2.DataBind();
                ASPxGridViewExporter1.GridViewID = "gvQuanNianYSQKtab2";
                sName = "全年用水情况";
                gvQuanNianYSQKtab2.Settings.ShowFooter = false;
            }
            else if (index == 2)
            {
                gvYueYongSQKtab3.DataSource = this.dtYueYongSQKtab3;
                gvYueYongSQKtab3.DataBind();
                ASPxGridViewExporter1.GridViewID = "gvYueYongSQKtab3";
                sName = "月用水情况";
                gvYueYongSQKtab3.Settings.ShowFooter = false;
            }
            else if (index == 3)
            {
                gvYueYongSHZtab4.DataSource = this.dtYueYongSQKHZtab4;
                gvYueYongSHZtab4.DataBind();
                ASPxGridViewExporter1.GridViewID = "gvYueYongSHZtab4";
                sName = "月用水汇总";
                gvYueYongSHZtab4.Settings.ShowFooter = false;
            }
            else if (index == 4)
            {
                gvJiHuaBGtab5.DataSource = this.dtYongHuSFQKtab5;
                gvJiHuaBGtab5.DataBind();
                ASPxGridViewExporter1.GridViewID = "gvJiHuaBGtab5";
                sName = "用户收费情况";
                gvJiHuaBGtab5.Settings.ShowFooter = false;
            }
            else if (index == 5)
            {
                gvQuanNianSFHZtab6.DataSource = this.dtQuanNianSFHZtab6;
                gvQuanNianSFHZtab6.DataBind();
                ASPxGridViewExporter1.GridViewID = "gvQuanNianSFHZtab6";
                sName = "全年收费情况";
                gvQuanNianSFHZtab6.Settings.ShowFooter = false;
            }
            else if (index == 6)
            {
                gvYeWuYSFQKtab7.DataSource = this.dtYeWuYSFQKtab7;
                gvYeWuYSFQKtab7.DataBind();
                ASPxGridViewExporter1.GridViewID = "gvYeWuYSFQKtab7";
                sName = "业务员收费情况";
                gvYeWuYSFQKtab7.Settings.ShowFooter = false;
            }
            else if (index == 7)
            {
                gvXinKaoHYHHZtab8.DataSource = this.dtXinKaoHYHHZtab8;
                gvXinKaoHYHHZtab8.DataBind();
                ASPxGridViewExporter1.GridViewID = "gvXinKaoHYHHZtab8";
                sName = "新考核用户汇总";
                gvXinKaoHYHHZtab8.Settings.ShowFooter = false;
            }

            ASPxGridViewExporter1.WriteXlsToResponse(sName);
        }
    }
}